package simpleparallel;

public class Main implements Runnable{
   
    private Object lock = new Object();
    private int count = 0;
    private static Main inst = new Main();

    /**
     * @param args
     */
    public static void main(String[] args) {
        new Thread(inst).start();
        new Thread(inst).start();
    }

    public void run() {
        //keep increasing count by one every few seconds

        while(true){
            synchronized(lock){
                count++;
                System.out.println(Thread.currentThread().getName() + " increased count to:"+count);
            }
            try{
                Thread.sleep((int)(5000*Math.random()));
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
       
    }

}
